<!--conf
<sample in_favorites="false">
              <product version="1.5" edition="pro"/>
                     <modifications>
                            <modified date="070101"/>
                     </modifications>
               </sample>
 --> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
	<title>DHTML Tree + Grid sample</title>
</head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<link rel="stylesheet" type="text/css" href="../../../codebase/dhtmlx.css"/>
	<script src="../../../codebase/dhtmlx.js"></script>
<body onLoad="doOnLoad()">
	<h1>Tree + Grid</h1>
	<p>Implementing both dhtmlxTree & dhtmlxGrid in your application you can improve flexibility and functionality of its user interface by interacting between these components.<br> 
	Drag-and-drop elements from the tree into the grid and vice versa. </p>

   
	<script>
		var mygrid,tree;
		function doOnLoad(){
			mygrid = new dhtmlXGridObject('gridbox');
			tree=new dhtmlXTreeObject("treeboxbox_tree","100%","100%",0);
			tree.setSkin('dhx_skyblue');
			setTimeout("buildTree()",10)
			setTimeout("buildGrid()",11)
		}
		function buildTree(){
			
			tree.setImagePath("../../../codebase/imgs/dhxtree_skyblue/");
			tree.enableDragAndDrop(true);
			tree.loadXML("../common/tree.xml")
    		tree.setSerializationLevel(true,true);
		}
		function buildGrid(){
			//set grid parameters
			mygrid.selMultiRows = true;
			mygrid.setImagePath("../../../codebase/imgs/");
			var flds = "Sales,Book Title,Author,Price";
			mygrid.setHeader(flds);
			mygrid.setInitWidths("50,150,120,*")
			mygrid.setColAlign("right,left,left,right")
			mygrid.setColTypes("dyn,ed,ed,price");
			mygrid.setColSorting("int,str,str,int")
			mygrid.enableDragAndDrop(true);
			//start grid
			mygrid.init();
			mygrid.setSkin("dhx_skyblue")
			mygrid.loadXML("../common/grid.xml");
			mygrid.treeToGridElement = function(treeObj,treeNodeId,gridRowId){
				return [0,treeObj.getItemText(treeNodeId)];
			}

			//redefine grid-to-tree drop element
			mygrid.gridToTreeElement = function(treeObj,treeNodeId,gridRowId){
				return this.cells(gridRowId,1).getValue()+"/"+this.cells(gridRowId,2).getValue();
			}
			mygrid.attachEvent("onGridReconstructed",function(){this.setSizes()})

            mygrid.rowToDragElement = function (id){
                if(this.cells(id,2).getValue()!="")
         			return this.cells(id,2).getValue()+"/"+this.cells(id,1).getValue();
       			return this.cells(id,1).getValue();
            }
		}
	</script>
	<table>
		<tr>
			<td valign="top">
				<div id="treeboxbox_tree" style="width:260px; height:250px;background-color:#f5f5f5;border :1px solid Silver;; overflow:auto;"/>
			</td>
			<td valign="top">&nbsp;&nbsp;&nbsp;&nbsp;
			</td>
            <td valign="top">
                <div id="gridbox" width="400px" height="260px" style="background-color:white;overflow:hidden"></div>
            </td>
		</tr>
		
	</table>
	

</body>
</html>
